<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0%;
            box-sizing: border-box;
        }
        .box{
            width: 400px;
            height: 300px;
            background-color: antiquewhite;
            margin: 50px auto;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        input{
            width: 300px;
            height: 40px;
            padding: 10px;
            line-height: 20px;
            margin-top: 20px;
        }
        p{
            width:300px;
            height:30px;
            font-size: 16px;
            display: none;
            justify-content: center;
            align-items: center;
        }
        span{
            width: 40px;
            height: 20px;
            font-size: 12px;
            border: 1px solid;
            text-align: center;
            line-height: 20px;
        }
        span:first-child{
            margin-left: 5px;
            border-right: 0;
        }

        span:nth-child(3){
            border-left: 0px;
        }
        .wek{
            background: red;
        }
        .mid{
            background-color: yellow;
        }
        .str{
            background-color: green;
        }
    </style>
</head>
<body>
    <div class="box">
        <input type="text" placeholder="请输入密码">
        <p>您的密码强度为:<span>弱</span><span>中</span><span>强</span> </p>
    </div>
    <script src="../js/tools.js"></script>
    <script>
        let str=/^(?![a-zA-Z]+$)(?![A-Z0-9]+$)(?![A-Z\W_!@#$%^&*`~()-+=]+$)(?![a-z0-9]+$)(?![a-z\W_!@#$%^&*`~()-+=]+$)(?![0-9\W_!@#$%^&*`~()-+=]+$)[a-zA-Z0-9\W_!@#$%^&*`~()-+=]{8,30}$/;
        let mid=/^(?![a-zA-z]+$)(?!\d+$)(?![!@#$%^&*]+$)[a-zA-Z\d!@#$%^&*]+$/
        let wek=/^(?:\d+|[a-zA-Z]+|[!@#$%^&*]+)$/
        let Wek=$("p span:nth-child(1)")
        let Mid=$("p span:nth-child(2)")
        let Str=$("p span:nth-child(3)")
        let p=$('p')
        let password=$("input")
        password.onblur=function(){
            p.style.display="flex";
                Str.setAttribute("class","span")
                Mid.setAttribute("class","span")
                Wek.setAttribute("class","span")
            if(str.test(this.value)){
                Str.setAttribute("class","str")
                Mid.setAttribute("class","str")
                Wek.setAttribute("class","str")
            }else if(mid.test(this.value)){
                Mid.setAttribute("class","mid")
                Wek.setAttribute("class","mid")
            }else{
                Wek.setAttribute("class","wek")
            }
            
        }

    </script>
</body>
</html>